<?php
/**
 * User: hda
 * Date: 2017/4/17
 * Time: 10:58
 * Progress: 0%
 */

namespace app\index\controller;

use icontroller\admin\AController;
use icontroller\admin\index\IAdmin;
use library\request\Ip;
use logic\admin\index\LAdmin;
use model\AdminRole;
use think\Config;
use think\Cookie;

class Admin extends AController implements IAdmin
{
    private $logic;
    public function __construct()
    {
        parent::__construct();
        $this->logic=new LAdmin();
    }

    public function index()
    {
        return view();
    }

    public function index_data(){
        $param=array(
            'keyword'=>input('keyword'),
            'limit'=>input('limit'),
            'offset'=>input('offset'),
            'ordinal'=>input('ordinal'),
            'order'=>input('order'),
        );
        $data=$this->logic->index_data($param);
        return $data;
    }

    function add()
    {
       return view();
    }

    function insert()
    {
        $param=array(
            'nick'=>input('nick'),
            'password'=>input('password'),
            'name'=>input('name'),
            'mobile'=>input('mobile'),
            'flag_lock'=>input('flag_lock'),
        );
        $data=$this->logic->insert_data($param);
        return $data;
    }

    function edit()
    {
        $id=input('id');
        $data=$this->logic->edit_data($id);
        $this->assign('data',$data);
        return view();
    }

    function update()
    {
        $id=input('id');
        $param=array(
            'nick'=>input('nick'),
            'name'=>input('name'),
            'mobile'=>input('mobile'),
            'flag_lock'=>input('flag_lock')
        );
        return $this->logic->update_data($id,$param);
    }

    function delete()
    {
        $id=input('id');
        return $this->logic->delete_data($id);
    }

    function role(){
        $admin_id=input('id');
        $data=$this->logic->get_admin_data($admin_id);
        $this->assign('admin',$data);
        return view();
    }
    function role_data(){
        $param=array(
            'keyword'=>input('keyword'),
            'limit'=>input('limit'),
            'offset'=>input('offset'),
            'ordinal'=>input('ordinal'),
            'order'=>input('order'),
        );
        return $this->logic->role_index_data($param);

    }

    function role_update(){
        $id=input('admin_id');
        $param=array(
            'role_id'=>input('role_id')
        );
        return $this->logic->admin_role_update($id,$param);
    }

    public function change_password(){
        $id=input('id');
        $this->assign('id',$id);
        return view();
    }

    public function change_password_save(){
       $id=input('id');
        $param=array(
            'old_password'=>input('old_password'),
            'new_password'=>input('new_password'),
            'confirm_password'=>input('confirm_password'),
        );
        return $this->logic->change_password_save($id,$param);
    }


}
